//
//  MNDTransactionFilterViewController.m
//  minidai
//
//  Created by Steven.Yung on 2017/5/18.
//  Copyright © 2017年 迷你金服. All rights reserved.
//

#import "MNDTransactionFilterViewController.h"
#import "UIButton+JKBackgroundColor.h"

@interface MNDTransactionFilterViewController ()

@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *buttons;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpaceConstraint;


@end

@implementation MNDTransactionFilterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.topSpaceConstraint.constant = -150.0;
    
    for (UIButton *button in self.buttons) {
        [button setBackgroundImage:[UIImage imageNamed:@"record_filter_default"] forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageNamed:@"record_filter_selected"] forState:UIControlStateSelected];
        [button setBackgroundImage:[UIImage imageNamed:@"record_filter_selected"] forState:UIControlStateHighlighted];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        [button setTitleColor:[UIColor colorWithRed:101/255.0 green:101/255.0 blue:101/255.0 alpha:1.0] forState:UIControlStateNormal];
    }
    
    self.topSpaceConstraint.constant = -205.0;
    
    UITapGestureRecognizer *tapRecorgnizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundTapAction:)];
    [self.view addGestureRecognizer:tapRecorgnizer];
}

- (void)setSelectedIndex:(NSInteger)selectedIndex {
    _selectedIndex = selectedIndex;
    
    for (UIButton *button in self.buttons) {
        [button setSelected:(self.selectedIndex + 100 == button.tag)];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [UIView animateWithDuration:5 animations:^{
        self.topSpaceConstraint.constant = 92.0;
    }];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    self.topSpaceConstraint.constant = -150.0;
    
    [UIView animateWithDuration:2 animations:^{
        self.topSpaceConstraint.constant = 0.0;
    }];
}

- (void)backgroundTapAction:(UITapGestureRecognizer *)gestureRecognizer {
    [self.view removeFromSuperview];
    [self removeFromParentViewController];
}

- (IBAction)buttonAction:(UIButton *)sender {
    
    for (UIButton *button in self.buttons) {
        if (button == sender) {
            button.layer.borderColor = kColorOrange.CGColor;
            [button setSelected:YES];
        } else {
            [button setSelected:NO];
            button.layer.borderColor = kColorLightGray.CGColor;
        }
    }
    
    if (self.filterDidSelectedBlock) {
        self.filterDidSelectedBlock(sender.tag);
    }
    [self.view removeFromSuperview];
    [self removeFromParentViewController];

}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
